<template>
    <a-form-item :label="itemOptions.label ? itemOptions.label :''">
      <j-input v-if="isJInput" v-model="currentVal" v-bind="bindProps" />
      <a-input v-if="isAInput" v-model="currentVal" v-bind="bindProps" />
      <a-select v-if="isASelect" v-model="currentVal" v-bind="bindProps">
        <a-select-option value>请选择{{currentVal}}</a-select-option>
        <a-select-option
          v-for="(itemSelect,indexSelect) in itemOptions.options"
          :key="indexSelect"
          :value="itemSelect.value"
        >{{itemSelect.label}}</a-select-option>
      </a-select>
    </a-form-item>
</template>

<script>
import JInput from '@/components/szxc/JInput'
export default {
  name: 'FormItem',
  components: { JInput },
  props: {
    value: {},
    itemOptions: {
      type: Object,
      required: true,
      default() {
        return []
      }
    }
  },
  computed: {
    // 双向绑定数据值
    currentVal: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      }
    },
    // 绑定属性
    bindProps() {
      let obj = { ...this.itemOptions }
      // 移除已使用的或不相关的冗余属性
      delete obj.label
      delete obj.prop
      delete obj.formType
      delete obj.initValue
      delete obj.rules
      delete obj.events
      if (obj.formType === 'a-select') {
        delete obj.options
       
      }
      return obj
    },
    //j-input
    isJInput() {
      return this.itemOptions.formType === 'jinput'
    },
    isAInput() {
      return this.itemOptions.formType === 'ainput'
    },
    isASelect() {
      return this.itemOptions.formType === 'aselect'
    }
  },
  data() {
    return {}
  }
}
</script>
<style>
</style>